import Vue from 'vue';
import App from './App';
import store from './store';
import filters from './filter/filter.js';
import { decideEnv, isIOS, setWxConfig, getUrlParam } from './unit/common.js';
import VueClipboard from 'vue-clipboard2'; // 复制插件
Vue.use(VueClipboard);
Vue.config.productionTip = false;
Vue.prototype.$store = store;

if (getUrlParam('token') && (window.location.href.split('#')[0].indexOf('/pages/join/result') !== -1 || window.location.href.split('#')[0].indexOf('/pages/property/myProperty') !== -1) ) {
  try {
      uni.setStorageSync('user_token', getUrlParam('token'));
      if (decideEnv() && decideEnv() === 'wx' && isIOS()) {
        Vue.prototype.$jswx = setWxConfig();
      }
      store.dispatch('getUserInfo');
  } catch (e) {
      // error
  }
} else if (!getUrlParam('token')) {
  try {
    const token = uni.getStorageSync('user_token');
    if (token) {
      if (decideEnv() && decideEnv() === 'wx' && isIOS()) {
        Vue.prototype.$jswx = setWxConfig();
      }
    }
    if (token && window.location.href.split('#')[0].indexOf('login') === -1 && window.location.href.split('#')[0].indexOf('join') === -1 && JSON.stringify(store.state.userInfo) === '{}') { // 有token且当前访问的页面不是免登录页面的情况下需要判断当前用户等级是否达到系统等级要求,否则跳到加盟入驻页面
      store.dispatch('getUserInfo');
    }
  } catch (e) {
    // error
  }
}

Object.keys(filters).forEach(key => Vue.filter(key, filters[key]));

App.mpType = 'app';

const app = new Vue({
  store,
  ...App
});
app.$mount();
